package org.tobaccomain.controller;

import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import org.tobaccomain.pojo.dto.RfidDTO;
import org.tobaccomain.pojo.entity.*;
import org.tobaccomain.service.DeskService;

import java.io.IOException;
import java.util.List;

@Slf4j
@RestController
public class DeskController {
    @Resource
    private DeskService deskService;

    //获取的单料烟概览数据
    @GetMapping("/desk/overview")
    public Result getOverview(){
        OverviewData overviewData = deskService.getOverview();
        return Result.success(overviewData);
    }

    //获取单料烟年份数据
    @GetMapping("/desk/year")
    public Result getYearData(){
        List<YearData> list = deskService.getYearData();
        return Result.success(list);
    }

    //获取各个产地的单料烟数量
    @GetMapping("/desk/location/number")
    public Result getNumberOfLocation(){
        List<LocationData> list = deskService.getNumberOfLocation();
        return Result.success(list);
    }

    //获取全部的rfid号
    @RequestMapping("/rfid/all")
    public Result getAllRfidList(){
        List<RfidDTO> rfids = deskService.getAllRfidList();
        return Result.success(rfids);
    }

    //获取可用的rfid号
    @RequestMapping("/rfid/available")
    public Result getAvailableRfidList(){
        List<RfidDTO> rfids = deskService.getAvailableRfidList();
        return Result.success(rfids);
    }

    //rfid数据导入
    @PostMapping("/rfid/upload")
    public Result uploadRfid(MultipartFile file) throws IOException {
        deskService.uploadRfid(file);
        return Result.success("rfid数据导入成功");
    }


}
